package com.copractice.data.entity.tag;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import com.copractice.data.entity.PersistentObject;

/**
 * Represents tag entity.
 *
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 03/19/2009
 */
@Entity
@Table(name = "TAGS")
@NamedQueries(
{
    @NamedQuery(name="TAGS.findByTagName",query="select u from Tag u where u.name = ?"),
    @NamedQuery(name="TAGS.findTagsByQuestion", 
                query="select t from Tag t where t.id IN (select qt.tagsId from QuestionsTags qt where qt.questionsId = ?)")        
})   
@SuppressWarnings("serial")
public class Tag extends PersistentObject {

    /**
     * Name of a tag
     */
    private String name;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Override
    public Long getId() {
        return super.getId();
    }
    
    /**
     * Returns name of a tag
     *
     * @return the <code>String</code> containing tags name
     */
    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    /**
     * Sets tags name
     *
     * @param name the <code>String</code> which contains tags name
     */
    public void setName(String name) {
        this.name = name;
    }    
    
}
